'use strict';

function Util(){
    this.name = 'util';
    this.toast = function(msg, tabId){
        chrome.tabs.executeScript(tabId, {code:createToast(msg)});
        chrome.tabs.insertCSS(tabId,{file:'css/inject.css'});
    };
    this.executeScript = async (opt)=>{
        let rs;
        await chrome.tabs.executeScript({ file: 'js/bbs/gfan/tabs/queryReplyParamsFastPost.js' }, (arr) => rs = arr);
        return rs;
    }

    function createToast(msg){
        return `
        (
            ()=>{
                let ceToastContainer = document.getElementById('chrome-extension-toast-container');
                if(ceToastContainer){
                   let newDiv = document.createElement('div');
                   newDiv.innerText = '${msg}';
                   ceToastContainer.appendChild(newDiv);
                   setTimeout(() => {
                        ceToastContainer.removeChild(newDiv);
                    }, 2000);
                }else{
                    ceToastContainer = document.createElement('div');
                    ceToastContainer.id = 'chrome-extension-toast-container';
                    let newDiv = document.createElement('div');
                    newDiv.innerText = '${msg}';
                    ceToastContainer.appendChild(newDiv);
                    document.body.appendChild(ceToastContainer);
                    setTimeout(() => {
                            ceToastContainer.removeChild(newDiv);
                        }, 2000);
                }
                
            }
        )();
        `
    }
}